package com.feituan.manager.controller;


import com.feituan.core.persistence.service.ICateService;
import com.feituan.core.persistence.service.ICouponService;
import com.feituan.core.pojo.entity.Cate;
import com.feituan.core.pojo.entity.Coupon;
import com.feituan.core.pojo.request.CommonPageReq;
import com.feituan.core.pojo.request.CouponSaveReq;
import com.feituan.core.pojo.response.Response;
import com.feituan.core.pojo.response.page.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Calendar;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaohu
 * @since 2024-05-09
 */
@RestController
@RequestMapping("/cate")
@Api(tags = "商品分类管理")
public class CateController  extends BaseController{
    @Autowired
    private ICateService iCateService;
    @PostMapping("/list_page")
    @ApiOperation("")
    public Response<PageData<Cate>> listPage(@Valid CommonPageReq request) {
        setDefaultPageParameters(request);
        return Response.success(iCateService.queryPage(request));
    }

    @PostMapping("/save")
    @ApiOperation("id为空新增，id不为空修改")
    public Response<Boolean> save(@Valid Cate request) {
        Cate coupon=new Cate();
        BeanUtils.copyProperties(request,coupon);
        if(coupon.getId() == null){
            coupon.setCreateTime(Calendar.getInstance().getTime());
            return response(iCateService.save(coupon)) ;
        }else{
            coupon.setCreateTime(null);
            return response(iCateService.updateById(coupon));
        }
    }
    @PostMapping("/delete")
    @ApiOperation("")
    public Response<Boolean> delete(Long id) {
        return response(iCateService.removeById(id));
    }
}
